<template>
  <div>
    <h2>您的所在地:</h2>
    <h2>{{ province }}{{ city }}{{ district }}</h2>
    <el-button type="text" @click="getLocation()">重新定位</el-button>
  </div>
</template>

<script>
import {location} from "../tool/lacation";

export default {
  name: "MyMap",
  data() {
    return {
      country: '',
      province: '',
      city: '',
      district: '',
    }
  },
  methods: {
    getLocation() {
      let _that = this;
      let geolocation = location.initMap("map-con"); //定位
      AMap.event.addListener(geolocation, "complete", (result) => {
        console.log(result);
        _that.province = result.addressComponent.province;
        _that.city = result.addressComponent.city;
        _that.district = result.addressComponent.district;
      });
    }
  },
  mounted() {
    this.getLocation()
  }
}
</script>

<style scoped>

</style>